﻿//功能描述：绩效管理：项目人员进度和项目考核记录
using Hong.IRepository.IRepository_AssessmentManagement;
using Hong.Model.SysDomain.Model_AssessmentManagement;
using Hong.Model.SysDomain.Model_AssessmentManagement.ViewPrjectList;
using Hong.Repository.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hong.Repository.Repository.Repository_AssessmentManagement
{
    public class AssProgresRepository : IAssProgresRepository
    {
        #region 构造器注入
        private readonly T_HongShi_3Context _dal;
        public AssProgresRepository(T_HongShi_3Context dal)
        {
            _dal = dal;
        }
        #endregion
        #region 项目人员进度和项目考核记录显示
        /// <summary>
        /// 项目人员进度和项目考核记录显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<ViewPrjectLists> GetViewPrjectLists(string id, out int totalCount, int pageIndex=1,int pageSize=8)
        {
            var list1 = _dal.AssessmentLists.ToList();//考核任务
            var list2 = _dal.AssessmentPrjecs.ToList();//大考核项目
            var list3 = _dal.AssSmaliProjecs.ToList();//小考核项目
            var list4 = _dal.AssProgresses.ToList();//项目考核记录
            var quey = from a in list1
                       join b in list2 on a.AssId equals b.AssPrjectListId
                       join c in list3 on b.AssPrjectId equals c.AssPrjectId
                       join d in list4 on c.PrId equals d.ProAssProId
                       select new ViewPrjectLists
                       {
                           AssId = a.AssId,
                           AssStartTime = a.AssStartTime,
                           AssEndTime = a.AssEndTime,
                           AssBeiZhu = a.AssBeiZhu,
                           AssProject = a.AssProject,
                           AssDepartment = a.AssId,
                           AssFile = a.AssFile,
                           AssCreateTime = a.AssCreateTime,
                           AssValue = a.AssValue,
                           AssEntry = a.AssEntry,
                           AssTotalWages = a.AssTotalWages,
                           AssAvgWages = a.AssAvgWages,

                           AssPrjectId = b.AssPrjectId,
                           AssPrjectName = b.AssPrjectName,
                           AssPrjectListId = b.AssPrjectListId,
                           AssPrjectPartState = b.AssPrjectPartState,
                           AssStart = b.AssStart,
                           AssbonusStart = b.AssbonusStart,

                           PrId = c.PrId,
                           PrName = c.PrName,
                           PrPerformance = c.PrPerformance,
                           PrNote = c.PrNote,
                           PrFinished = c.PrFinished,
                           PrUnfinished = c.PrUnfinished,
                           PrHistory = c.PrHistory,
                           PrTotal = c.PrTotal,


                           ProId = d.ProId,
                           ProHost = d.ProHost,
                           ProDivision1 = d.ProDivision1,
                           ProChief1 = d.ProChief1,
                           ProConstruction = d.ProConstruction,
                           ProDivision2 = d.ProDivision2,
                           ProChief2 = d.ProChief2,
                           ProStructure = d.ProStructure,
                           ProDivision3 = d.ProDivision3,
                           ProHvac = d.ProHvac,
                           ProDivision4 = d.ProDivision4,
                           ProDrainage = d.ProDrainage,
                           ProDivision5 = d.ProDivision5,
                           ProAppliance = d.ProAppliance,
                           ProDivision6 = d.ProDivision6,
                           ProStart = d.ProStart,
                           ProAssProId = d.ProAssProId,
                       };
            if (!string.IsNullOrEmpty(id))
            {
                quey = quey.Where(x => x.AssId == id);
            }
            totalCount = quey.Count();
            quey = quey.Skip((pageIndex - 1) * pageSize).Take(pageSize);
         
            return quey.ToList();
        }

        #region 反填
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<AssProgress> GetAssProgressFT(int id)
        {
            var list = _dal.AssProgresses.Where(x => x.ProId == id).ToList();
            return list;
        }
        #endregion

        #region 审批状态
        /// <summary>
        /// 审批状态
        /// </summary>
        /// <returns></returns>
        public int PutAssProgress(int id)
        {
            var obj = _dal.AssProgresses.FirstOrDefault(x => x.ProId == id);
            obj.ProStart = false;
            var i= _dal.SaveChanges();
            return i;
        }
        #endregion

        #region 批量发起
        /// <summary>
        /// 批量发起
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public int PutAssProgress1(string ids)
        {
            string[] str = ids.Split(',');
            foreach (var item in str)
            {
                var obj = _dal.AssProgresses.FirstOrDefault(x => x.ProId == Convert.ToInt32(item));
                obj.ProStart = true;
            }
            return _dal.SaveChanges();
        }
        #endregion

        #endregion
    }
}